function ClearInstitutionFields(){
    document.forms[0].action = "ClearInstitution.action";
    document.forms[0].submit();
    return false;
}

function ClearSubInstitutionFields(){
    document.forms[0].action = "ClearSubInstitution.action";
    document.forms[0].submit();
    return false;
}

function ClearDepartmentFields(){
    document.forms[0].action = "ClearDepartment.action";
    document.forms[0].submit();
    return false;
}

function getSubinstitutionList(SourceListID, DestinationListID){     
    var searchValue = document.getElementById(SourceListID).value;
    if (searchValue != "") {
        var msg = $.ajax({
            url:"/pico/ajax/getSubinstitutionList.action?searchValue=" + searchValue,
            async:false
        }).responseText;                
        var listText = unescape(msg);
        var TypeArray = new Array();
        var TypeArrayInfo = new Array();

        TypeArray = listText.split(",");
        document.getElementById(DestinationListID).options.length = 0;
        document.getElementById(DestinationListID).options.add(new Option("-- Please Select --", ""));
        
        for (i = 0; i < TypeArray.length; i++) {
            TypeArrayInfo = TypeArray[i].split("|");
            document.getElementById(DestinationListID).options.add(new Option(TypeArrayInfo[1], TypeArrayInfo[0]));
        }
    }
    else{
        document.getElementById(DestinationListID).options.length = 0;
        document.getElementById(DestinationListID).options.add(new Option("-- Please Select --", ""));
    }
}


function getDepartmentList(SourceListID, DestinationListID){

    var searchValue = document.getElementById(SourceListID).value;

    if (searchValue != "") {
        var msg = $.ajax({
            url:"/pico/ajax/getDepartmentList.action?searchValue=" + searchValue,
            async:false
        }).responseText;

        var listText = unescape(msg);
        var TypeArray = new Array();
        var TypeArrayInfo = new Array();

        TypeArray = listText.split(",");
        document.getElementById(DestinationListID).options.length = 0;
        document.getElementById(DestinationListID).options.add(new Option("-- Please Select --", ""));
        for (i = 0; i < TypeArray.length; i++) {
            TypeArrayInfo = TypeArray[i].split("|");
            document.getElementById(DestinationListID).options.add(new Option(TypeArrayInfo[1], TypeArrayInfo[0]));
        }
    }
    else{
        document.getElementById(DestinationListID).options.length = 0;
        document.getElementById(DestinationListID).options.add(new Option("-- Please Select --", ""));
    }
}

function getInstitutionUserRoleList(SourceListID, DestinationListID){

    var searchValue = document.getElementById(SourceListID).value;

    if (searchValue != "") {
        var msg = $.ajax({
            url:"/pico/ajax/getInstitutionUserRoleList.action?searchValue=" + searchValue,
            async:false
        }).responseText;
        var listText = unescape(msg);
        var TypeArray = new Array();
        var TypeArrayInfo = new Array();
        TypeArray = listText.split(",");
        document.getElementById(DestinationListID).options.length = 0;
        document.getElementById(DestinationListID).options.add(new Option("-- Please Select --", ""));
        for (i = 0; i < TypeArray.length; i++) {
            TypeArrayInfo = TypeArray[i].split("|");
            document.getElementById(DestinationListID).options.add(new Option(TypeArrayInfo[1], TypeArrayInfo[0]));
        }
    }
    else{
        document.getElementById(DestinationListID).options.length = 0;
        document.getElementById(DestinationListID).options.add(new Option("-- Please Select --", ""));
    }
}

function SetInstitutionDependenetLists_UserProfile(SourceListID, DestinationListID){
    //Set Sub Institutions List
    getSubinstitutionList(SourceListID, DestinationListID);
    //Set Departments to Blank List
    document.getElementById("SaveUserProfile_erpmur_departmentmaster_dmId").options.length = 0;
    document.getElementById("SaveUserProfile_erpmur_departmentmaster_dmId").options.add(new Option("-- Please Select --", ""));
    //Reset User Role List
    getInstitutionUserRoleList(SourceListID, "SaveUserProfile_erpmur_institutionuserroles_iurId")
}

function SetInstitutionList(DestinationListID) {        
        var msg = $.ajax({
            url:"/pico/ajax/getInstitutions.action",
            async:false
        }).responseText;        
        var listText = unescape(msg);
        var TypeArray = new Array();
        var TypeArrayInfo = new Array();
        TypeArray = listText.split(",");
        document.getElementById(DestinationListID).options.length = 0;
        document.getElementById(DestinationListID).options.add(new Option("-- Please Select --", ""));
        for (i = 0; i < TypeArray.length; i++) {
            TypeArrayInfo = TypeArray[i].split("|");
            document.getElementById(DestinationListID).options.add(new Option(TypeArrayInfo[1], TypeArrayInfo[0]));
        }
    }


function RetrieveSQ(UserName, DOB, SecretQuestion){
   var UName = document.getElementById(UserName).value;
   var DateofBirth = document.getElementById(DOB).value;

    if (UName == "" || DateofBirth == "")
        document.getElementById(SecretQuestion).setAttribute("value","Please provide values for the above fields");
    else
    {
        var msg = $.ajax({
            url:"/pico/ajax/getSecretQuestion.action?searchValue=" + UName +"&searchValue2="+DateofBirth,
            async:false
        }).responseText;   
        document.getElementById(SecretQuestion).setAttribute("value",msg);
    }
}